package com.ecfront.test.dao;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import com.ecfront.dao.GoodsSortDAO;
import com.ecfront.pojo.Goods;
import com.ecfront.pojo.GoodsBrand;
import com.ecfront.pojo.GoodsSort;
import junit.framework.TestCase;

public class testGoodsSort extends TestCase {
	private static final GoodsSortDAO goodsSortDAO = (GoodsSortDAO)SpringUtilTest.getBean("GoodsSortDAO");
	//测试保存���Ա���
	public void testSave(){
		GoodsBrand goodsBrand = new GoodsBrand();
		goodsBrand.setId(1);
		
		GoodsSort goodsSort = new GoodsSort();
		goodsSort.setName("衣服");
		goodsSort.setGoodId(0);
		Set goodsBrandSet = new HashSet();
		
		goodsBrandSet.add(goodsBrand);
		goodsSort.setGoodsBrands(goodsBrandSet);
		
		goodsSortDAO.save(goodsSort);
	}
	
	//测试删除����ɾ��
	public void testDel(){
		GoodsSort goodsSort = new GoodsSort();
		goodsSort.setId(2);
		goodsSortDAO.delete(goodsSort);
	}
	//根据ID得到属性���ID�õ�����
	public void testFindById(){
		GoodsSort goodsSort = goodsSortDAO.findById(1);
		System.out.println(goodsSort.getName());
		
		Set goodsBrand = goodsSort.getGoodsBrands();
		for(Iterator iter = goodsBrand.iterator();iter.hasNext();){
			GoodsBrand gb = (GoodsBrand)iter.next();
			System.out.println(gb.getName());
		}
		System.out.println("类别全部商品测试！----------");
		Set goods = goodsSort.getGoods();
		for(Iterator iter = goods.iterator();iter.hasNext();){
			Goods gs = (Goods)iter.next();
			System.out.println(gs.getName());
		}
	}
}
